#include <iostream>
#include <memory>

// 策略接口
class Strategy
{
public:
    virtual ~Strategy() = default;
    virtual void execute() = 0;
};

// 具体策略A
class ConcreteStrategyA : public Strategy
{
public:
    void execute() override
    {
        std::cout << "执行策略A" << std::endl;
    }
};

// 具体策略B
class ConcreteStrategyB : public Strategy
{
public:
    void execute() override
    {
        std::cout << "执行策略B" << std::endl;
    }
};

// 上下文类
class Context
{
    std::unique_ptr<Strategy> strategy;

public:
    void setStrategy(std::unique_ptr<Strategy> s) { strategy = std::move(s); }
    void executeStrategy()
    {
        strategy->execute();
    }
};

// 使用示例
int main()
{
    Context context;
    context.setStrategy(std::make_unique<ConcreteStrategyA>());
    context.executeStrategy();
    context.setStrategy(std::make_unique<ConcreteStrategyB>());
    context.executeStrategy();
    return 0;
}
